package org.xdq.yzmdemo;

import java.util.Hashtable;

public class YzmCache {

    private static Hashtable<String,String> codeMap = new Hashtable();

    public static void add(String key,String textCode){

        codeMap.put(key,textCode);

        new Thread(()->{
            try {
                System.out.println(key+":"+textCode+" 30s后失效！");
                Thread.sleep(30*1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            codeMap.remove(key);
            System.out.println(key+":"+textCode+" 已失效！");
        }).start();
    }

    public static boolean verfyCode(String key,String clientCode){
        if(clientCode == null)return false;
        String textCode = codeMap.get(key);
        return clientCode.equalsIgnoreCase(textCode);
    }


}
